home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-11.z / elisp-11
Encoding:
GNU Info File  |  1994-08-02  |  48.6 KB  |  1,297 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Syntax Errors,  Next: Compilation Errors,  Prev: Debugger,  Up: Debugging
  41.  
  42. Debugging Invalid Lisp Syntax
  43. =============================
  44.  
  45.    The Lisp reader reports invalid syntax, but cannot say where the real
  46. problem is.  For example, the error "End of file during parsing" in
  47. evaluating an expression indicates an excess of open parentheses (or
  48. square brackets).  The reader detects this imbalance at the end of the
  49. file, but it cannot figure out where the close parenthesis should have
  50. been.  Likewise, "Invalid read syntax: ")"" indicates an excess close
  51. parenthesis or missing open parenthesis, but not where the missing
  52. parenthesis belongs.  How, then, to find what to change?
  53.  
  54.    If the problem is not simply an imbalance of parentheses, a useful
  55. technique is to try `C-M-e' at the beginning of each defun, and see if
  56. it goes to the place where that defun appears to end.  If it does not,
  57. there is a problem in that defun.
  58.  
  59.    However, unmatched parentheses are the most common syntax errors in
  60. Lisp, and we can give further advice for those cases.
  61.  
  62. * Menu:
  63.  
  64. * Excess Open::     How to find a spurious open paren or missing close.
  65. * Excess Close::    How to find a spurious close paren or missing open.
  66.  
  67. 
  68. File: elisp,  Node: Excess Open,  Next: Excess Close,  Up: Syntax Errors
  69.  
  70. Excess Open Parentheses
  71. -----------------------
  72.  
  73.    The first step is to find the defun that is unbalanced.  If there is
  74. an excess open parenthesis, the way to do this is to insert a close
  75. parenthesis at the end of the file and type `C-M-b' (`backward-sexp').
  76. This will move you to the beginning of the defun that is unbalanced.
  77. (Then type `C-SPC C-_ C-u C-SPC' to set the mark there, undo the
  78. insertion of the close parenthesis, and finally return to the mark.)
  79.  
  80.    The next step is to determine precisely what is wrong.  There is no
  81. way to be sure of this except to study the program, but often the
  82. existing indentation is a clue to where the parentheses should have
  83. been.  The easiest way to use this clue is to reindent with `C-M-q' and
  84. see what moves.
  85.  
  86.    Before you do this, make sure the defun has enough close parentheses.
  87. Otherwise, `C-M-q' will get an error, or will reindent all the rest of
  88. the file until the end.  So move to the end of the defun and insert a
  89. close parenthesis there.  Don't use `C-M-e' to move there, since that
  90. too will fail to work until the defun is balanced.
  91.  
  92.    Then go to the beginning of the defun and type `C-M-q'.  Usually all
  93. the lines from a certain point to the end of the function will shift to
  94. the right.  There is probably a missing close parenthesis, or a
  95. superfluous open parenthesis, near that point.  (However, don't assume
  96. this is true; study the code to make sure.)  Once you have found the
  97. discrepancy, undo the `C-M-q', since the old indentation is probably
  98. appropriate to the intended parentheses.
  99.  
  100.    After you think you have fixed the problem, use `C-M-q' again.  It
  101. should not change anything, if the problem is really fixed.
  102.  
  103. 
  104. File: elisp,  Node: Excess Close,  Prev: Excess Open,  Up: Syntax Errors
  105.  
  106. Excess Close Parentheses
  107. ------------------------
  108.  
  109.    To deal with an excess close parenthesis, first insert an open
  110. parenthesis at the beginning of the file and type `C-M-f' to find the
  111. end of the unbalanced defun.  (Then type `C-SPC C-_ C-u C-SPC' to set
  112. the mark there, undo the insertion of the open parenthesis, and finally
  113. return to the mark.)
  114.  
  115.    Then find the actual matching close parenthesis by typing `C-M-f' at
  116. the beginning of the defun.  This will leave you somewhere short of the
  117. place where the defun ought to end.  It is possible that you will find
  118. a spurious close parenthesis in that vicinity.
  119.  
  120.    If you don't see a problem at that point, the next thing to do is to
  121. type `C-M-q' at the beginning of the defun.  A range of lines will
  122. probably shift left; if so, the missing open parenthesis or spurious
  123. close parenthesis is probably near the first of those lines.  (However,
  124. don't assume this is true; study the code to make sure.)  Once you have
  125. found the discrepancy, undo the `C-M-q', since the old indentation is
  126. probably appropriate to the intended parentheses.
  127.  
  128. 
  129. File: elisp,  Node: Compilation Errors,  Next: Edebug,  Prev: Syntax Errors,  Up: Debugging
  130.  
  131. Debugging Problems in Compilation
  132. =================================
  133.  
  134.    When an error happens during byte compilation, it is normally due to
  135. invalid syntax in the program you are compiling.  The compiler prints a
  136. suitable error message in the `*Compile-Log*' buffer, and then stops.
  137. The message may state a function name in which the error was found, or
  138. it may not.  Regardless, here is how to find out where in the file the
  139. error occurred.
  140.  
  141.    What you should do is switch to the buffer ` *Compiler Input*'.
  142. (Note that the buffer name starts with a space, so it does not show up
  143. in `M-x list-buffers'.)  This buffer contains the program being
  144. compiled, and point shows how far the byte compiler was able to read.
  145.  
  146.    If the error was due to invalid Lisp syntax, point shows exactly
  147. where the invalid syntax was *detected*.  The cause of the error is not
  148. necessarily near by!  Use the techniques in the previous section to find
  149. the error.
  150.  
  151.    If the error was detected while compiling a form that had been read
  152. successfully, then point is located at the end of the form.  In this
  153. case, it can't localize the error precisely, but can still show you
  154. which function to check.
  155.  
  156. 
  157. File: elisp,  Node: Edebug,  Prev: Compilation Errors,  Up: Debugging
  158.  
  159. Edebug
  160. ======
  161.  
  162.    Edebug is a source-level debugger for Emacs Lisp programs that
  163. provides the following features:
  164.  
  165.    * Step through evaluation, stopping before and after each expression.
  166.  
  167.    * Set conditional or unconditional breakpoints.
  168.  
  169.    * Trace slow or fast stopping briefly at each stop point, or each
  170.      breakpoint.
  171.  
  172.    * Evaluate expressions as if outside of Edebug.
  173.  
  174.    * Automatically reevaluate a list of expressions and display their
  175.      results each time Edebug updates the display.
  176.  
  177.    * Output trace info on function enter and exit.
  178.  
  179.    The first three sections of this chapter should tell you enough about
  180. Edebug to enable you to use it.
  181.  
  182. * Menu:
  183.  
  184. * Using Edebug::        Introduction to use of Edebug.
  185. * Prepare: Edebug Prepare.    You must prepare a function or macro definition
  186.                   in order to debug it with Edebug.
  187. * Edebug Modes::        Execution modes, stopping more or less often.
  188. * Stepping::            Commands to step to a specified place.
  189. * Breakpoints::            Setting breakpoints to make the program stop.
  190. * Views::            Viewing the outside buffer and window status.
  191. * Eval: Edebug Eval.        Evaluating expressions within Edebug.
  192. * Eval List::            Expressions whose values are displayed
  193.                   each time you enter Edebug.
  194. * Misc: Edebug Misc.        Miscellaneous
  195. * Printing::            Printing circular structure in Edebug.
  196. * The Outside Context::        Data that Edebug saves and restores.
  197. * Macro Calls::            Explaining how to handle macro calls.
  198. * Options: Edebug Options.    Option variables for customizing Edebug.
  199.  
  200. 
  201. File: elisp,  Node: Using Edebug,  Next: Edebug Prepare,  Up: Edebug
  202.  
  203. Using Edebug
  204. ------------
  205.  
  206.    To debug a Lisp program with Edebug, you must first "prepare" the
  207. Lisp functions that you want to debug.  *Note Edebug Prepare::.
  208.  
  209.    Once a function is prepared, any call to the function activates
  210. Edebug.  This involves entering a recursive edit which is a level of
  211. Edebug activation.
  212.  
  213.    Activating Edebug may stop execution and let you step through the
  214. function, or it may continue execution while checking for debugging
  215. commands, depending on the selected Edebug execution mode.  *Note
  216. Edebug Modes::.
  217.  
  218.    Within Edebug, you normally view an Emacs buffer showing the source
  219. of the Lisp function you are debugging.  We call this the "Edebug
  220. buffer"--but note that it is not always the same buffer, and it is not
  221. reserved for Edebug use.
  222.  
  223.    An arrow at the left margin indicates the line where the function is
  224. executing.  Point initially shows where within the line the function is
  225. executing, but this ceases to be true if you move point yourself.
  226.  
  227.    If you prepare the definition of `fac' (shown below) for Edebug and
  228. then execute `(fac 3)', here is what you normally see.  Point is at the
  229. open-parenthesis before `if'.
  230.  
  231.      (defun fac (n)
  232.      =>-!-(if (< 0 n)
  233.            (* n (fac (1- n)))
  234.          1))
  235.  
  236.    The places within a function where Edebug can stop execution are
  237. called "stop points".  These occur both before and after each
  238. subexpression that is a list, and also after each variable reference.
  239. Stop points before variables are optional, under the control of the
  240. value of `edebug-stop-before-symbols'.  Here we show with periods the
  241. stop points normally found in the function `fac':
  242.  
  243.      (defun fac (n)
  244.        .(if .(< 0 n.).
  245.            .(* n. .(fac (1- n.).).).
  246.          1).)
  247.  
  248.    While a buffer is the Edebug buffer, the special commands of Edebug
  249. are available in it, instead of many usual editing commands.  Type `?'
  250. to display a list of Edebug commands.  In particular, you can exit the
  251. innermost Edebug activation level with `C-]', and you can return all
  252. the way to top level with `q'.
  253.  
  254.    For example, you can type the Edebug command SPC to execute until
  255. the next stop point.  If you type SPC once after entry to `fac', here
  256. is the state that you get:
  257.  
  258.      (defun fac (n)
  259.      =>(if -!-(< 0 n)
  260.            (* n (fac (1- n)))
  261.          1))
  262.  
  263.    When Edebug stops execution after an expression, it displays the
  264. expression's value in the echo area.  Use the `r' command to display
  265. the value again later.
  266.  
  267.    While Edebug is active, it catches all errors (if `debug-on-error' is
  268. non-`nil') and quits (if `debug-on-quit' is non-`nil') instead of the
  269. standard debugger.  When this happens, Edebug displays the last stop
  270. point that it knows about.  This may be the location of a call to a
  271. function which was not prepared for Edebug debugging, within which the
  272. error actually occurred.
  273.  
  274. 
  275. File: elisp,  Node: Edebug Prepare,  Next: Edebug Modes,  Prev: Using Edebug,  Up: Edebug
  276.  
  277. Preparing Functions for Edebug
  278. ------------------------------
  279.  
  280.    In order to use Edebug to debug a function, you must first "prepare"
  281. the function.  Preparing a function inserts additional code into it
  282. which invokes Edebug at the proper places.
  283.  
  284.    Any call to an Edebug-prepared function activates Edebug.  This may
  285. or may not stop execution, depending on the Edebug execution mode in
  286. use.  Some Edebug modes only update the display to indicate the
  287. progress of the evaluation without stopping execution.  The default
  288. initial Edebug mode is `step' which does stop execution.  *Note Edebug
  289. Modes::.
  290.  
  291.    Once you have loaded Edebug, the command `C-M-x' is redefined so
  292. that when used on a function or macro definition, it prepares the
  293. function or macro if given a prefix argument.  If the variable
  294. `edebug-all-defuns' is non-`nil', that inverts the meaning of the
  295. prefix argument: then `C-M-x' prepares the function or macro *unless*
  296. it has a prefix argument.  The default value of `edebug-all-defuns' is
  297. `nil'.  The command `M-x edebug-all-defuns' toggles the value of the
  298. variable `edebug-all-defuns'.
  299.  
  300.    If `edebug-all-defuns' is non-`nil', then the commands `eval-region'
  301. and `eval-current-buffer' also prepare any functions and macros whose
  302. definitions they evaluate.
  303.  
  304.    Loading a file does not prepare functions and macros for Edebug.
  305.  
  306.    See *Note Evaluation:: for discussion of other evaluation functions
  307. available inside of Edebug.
  308.  
  309. 
  310. File: elisp,  Node: Edebug Modes,  Next: Stepping,  Prev: Edebug Prepare,  Up: Edebug
  311.  
  312. Edebug Modes
  313. ------------
  314.  
  315.    Edebug supports several execution modes for running the program you
  316. are debugging.  We call these alternatives "Edebug modes"; do not
  317. confuse them with major modes or minor modes.  The current Edebug mode
  318. determines how Edebug displays the progress of the evaluation, whether
  319. it stops at each stop point, or continues to the next breakpoint, for
  320. example.
  321.  
  322.    Normally, you specify the Edebug mode for execution by typing a
  323. command to continue the program in a certain mode.  Here is a table of
  324. these commands.  All except for `S' resume execution of the program, at
  325. least for a certain distance.
  326.  
  327. `S'
  328.      Stop: don't execute any more of the program for now, just wait for
  329.      more Edebug commands.
  330.  
  331. `SPC'
  332.      Step: stop at the next stop point encountered.
  333.  
  334. `t'
  335.      Trace: pause one second at each Edebug stop point.
  336.  
  337. `T'
  338.      Rapid trace: mention each stop point, but don't actually pause.
  339.  
  340. `g'
  341.      Go: run until the next breakpoint.  *Note Breakpoints::.
  342.  
  343. `c'
  344.      Continue: pause for one second at each breakpoint, but don't stop.
  345.  
  346. `C'
  347.      Continue: mention each breakpoint, but don't actually pause.
  348.  
  349. `G'
  350.      Non-stop: ignore breakpoints.  You can still stop the program by
  351.      typing `S'.
  352.  
  353.    In general, the execution modes earlier in the above list run the
  354. program more slowly or stop sooner.
  355.  
  356.    When you enter a new Edebug level, the mode comes from the value of
  357. the variable `edebug-initial-mode'.  By default, this specifies "step"
  358. mode.  If the mode thus specified is not stop mode, then the Edebug
  359. level executes the program (or part of it).
  360.  
  361.    While executing or tracing, you can interrupt the execution by typing
  362. any Edebug command.  Edebug stops the program at the next stop point and
  363. then executes the command that you typed.  For example, typing `t'
  364. during execution switches to trace mode at the next stop point.
  365.  
  366.    You can use the `S' command to stop execution without doing anything
  367. else.
  368.  
  369.    If your function happens to read input, a character you hit
  370. intending to interrupt execution may be read by the function instead.
  371. You can avoid such unintended results by paying attention to when your
  372. program wants input.
  373.  
  374.    Keyboard macros containing the commands in this section do not
  375. completely work: exiting from Edebug, to resume the program, loses
  376. track of the keyboard macro.  This is not easy to fix.
  377.  
  378. 
  379. File: elisp,  Node: Stepping,  Next: Breakpoints,  Prev: Edebug Modes,  Up: Edebug
  380.  
  381. Stepping
  382. --------
  383.  
  384. `f'
  385.      Run the program forward over one expression.  More precisely, set a
  386.      temporary breakpoint at the position that `C-M-f' would reach,
  387.      then execute in go mode so that the program will stop at
  388.      breakpoints.  See *Note Breakpoints:: for the details on
  389.      breakpoints.
  390.  
  391.      With a prefix argument N, the temporary breakpoint is placed N
  392.      sexps beyond point.  If the containing list ends before N more
  393.      elements, then the place to stop is after the containing
  394.      expression.
  395.  
  396.      Be careful that the position `C-M-f' finds is a place that the
  397.      program will really get to; this may not be true in a
  398.      `condition-case', for example.
  399.  
  400.      This command does `forward-sexp' starting at point rather than the
  401.      stop point, thus providing more flexibility.  If you want to
  402.      execute one expression from the current stop point, type `w'
  403.      first, to move point there.
  404.  
  405. `o'
  406.      Run the program until the end of the containing sexp.  If the
  407.      containing sexp is the top level defun, run until just before the
  408.      function returns.  If that is where you are now, return from the
  409.      function and then stop.
  410.  
  411.      This command does not exit the currently executing function unless
  412.      you are positioned after the last sexp of the function.
  413.  
  414.      If the program does a non-local exit, it may fail to reach the
  415.      temporary breakpoint that this command sets.
  416.  
  417. `i'
  418.      Step into the function about to be called.  Use this command
  419.      before any of the arguments of the function call are evaluated,
  420.      since otherwise it is too late.
  421.  
  422.      One undesirable side effect of using `edebug-step-in' is that the
  423.      next time the stepped-into function is called, Edebug will be
  424.      called there as well.
  425.  
  426. `h'
  427.      Proceed to the stop point near where point is.  This uses a
  428.      temporary breakpoint.
  429.  
  430.    The `f' command runs the program forward over one expression.  More
  431. precisely, set a temporary breakpoint at the position that `C-M-f'
  432. would reach, then execute in go mode so that the program will stop at
  433. breakpoints.  See *Note Breakpoints:: for the details on breakpoints.
  434.  
  435.    With a prefix argument N, the temporary breakpoint is placed N sexps
  436. beyond point.  If the containing list ends before N more elements, then
  437. the place to stop is after the containing expression.
  438.  
  439.    Be careful that the position `C-M-f' finds is a place that the
  440. program will really get to; this may not be true in a `condition-case',
  441. for example.
  442.  
  443.    The `f' command uses the existing value of point as the basis for
  444. setting the breakpoint, because that is more flexible.  To execute one
  445. expression *from the current stop point*, type `w' and then `f'.
  446.  
  447.    The `o' command continues "out of" an expression.  It places a
  448. temporary breakpoints at the end of the containing sexp.  If the
  449. containing sexp is the top level defun, it continues until just before
  450. the function returns.  If that is where you are now, it returns from the
  451. function and then stops.
  452.  
  453.    This command does not exit the currently executing function unless
  454. you are positioned after the last sexp of the function.
  455.  
  456.    The `i' command steps into the function about to be called.  Use
  457. this command before any of the arguments of the function call are
  458. evaluated, since otherwise it is too late.
  459.  
  460.    One undesirable side effect of using `i' is that the next time the
  461. stepped-into function is called, Edebug will be called there as well.
  462.  
  463.    The `h' command proceeds to the stop point near where point is,
  464. using a temporary breakpoint.
  465.  
  466.    All the commands in this section may fail to work as expected in case
  467. of nonlocal exit, because a nonlocal exit can bypass the temporary
  468. breakpoint where you expected the program to stop.
  469.  
  470. 
  471. File: elisp,  Node: Edebug Misc,  Next: Printing,  Prev: Eval List,  Up: Edebug
  472.  
  473. Miscellaneous
  474. -------------
  475.  
  476.    Some miscellaneous commands are described here.
  477.  
  478. `C-]'
  479.      Abort one level of Edebug activity.
  480.  
  481. `q'
  482.      Return to the top level editor command loop.  This exits all
  483.      recursive editing levels, including all levels of Edebug activity.
  484.  
  485. `r'
  486.      Redisplay the result of the previous expression in the echo area.
  487.  
  488. `d'
  489.      Display a backtrace, excluding Edebug's own functions for clarity.
  490.  
  491.      You cannot use debugger commands in the backtrace buffer in Edebug
  492.      as you would in the standard debugger.
  493.  
  494.      The backtrace buffer is killed automatically when you continue
  495.      execution.
  496.  
  497. 
  498. File: elisp,  Node: Breakpoints,  Next: Views,  Prev: Stepping,  Up: Edebug
  499.  
  500. Breakpoints
  501. -----------
  502.  
  503.    While using Edebug, you can specify "breakpoints" in the program you
  504. are testing: points where execution should stop.  You can set a
  505. breakpoint at any stop point, as defined in *Note Using Edebug::--even
  506. before a symbol.  For setting and unsetting breakpoints, the stop point
  507. that is affected is the first one at or after point in the Edebug
  508. buffer.  Here are the Edebug commands for breakpoints:
  509.  
  510. `b'
  511.      Set a breakpoint at the stop point at or after point.  If you use a
  512.      prefix argument, the breakpoint is temporary (it turns off the
  513.      first time it stops the program).
  514.  
  515. `u'
  516.      Unset the breakpoint (if any) at the stop point at or after the
  517.      current point.
  518.  
  519. `x COND RET'
  520.      Set a conditional breakpoint which stops the program only if COND
  521.      evaluates to a non-`nil' value.  If you use a prefix argument, the
  522.      breakpoint is temporary (it turns off the first time it stops the
  523.      program).
  524.  
  525. `B'
  526.      Move point to the next breakpoint in the current function
  527.      definition.
  528.  
  529.    While in Edebug, you can set a breakpoint with `b'
  530. (`edebug-set-breakpoint') and unset one with `u'
  531. (`edebug-unset-breakpoint').  First you must move point to a position
  532. at or before the desired Edebug stop point, then hit the key to change
  533. the breakpoint.  Unsetting a breakpoint that has not been set does
  534. nothing.
  535.  
  536.    Reevaluating the function with `edebug-defun' clears all breakpoints
  537. in the function.
  538.  
  539.    A "conditional breakpoint" tests a condition each time the program
  540. gets there, to decide whether to stop.  To set a conditional breakpoint,
  541. use `x', and specify the condition expression in the minibuffer.
  542.  
  543.    You can make both conditional and unconditional breakpoints
  544. "temporary" by using a prefix arg to the command to set the breakpoint.
  545. After breaking at a temporary breakpoint, it is automatically cleared.
  546.  
  547.    Edebug always stops or pauses at a breakpoint except when the Edebug
  548. mode is Go-nonstop.  In that mode, it ignores breakpoints entirely.
  549.  
  550.    To find out where your breakpoints are, use the `B'
  551. (`edebug-next-breakpoint') command, which moves point to the next
  552. breakpoint in the function following point, or to the first breakpoint
  553. if there are no following breakpoints.  This command does not continue
  554. execution--it just moves point in the buffer.
  555.  
  556. 
  557. File: elisp,  Node: Views,  Next: Edebug Eval,  Prev: Breakpoints,  Up: Edebug
  558.  
  559. Views
  560. -----
  561.  
  562.    These Edebug commands let you view aspects of the buffer and window
  563. status that obtained before entry to Edebug.
  564.  
  565. `v'
  566.      View the outside window configuration.
  567.  
  568. `p'
  569.      Temporarily display the outside current buffer with point at its
  570.      outside position.
  571.  
  572. `w'
  573.      Switch back to the buffer showing the currently executing
  574.      function, and move point back to the current stop point.
  575.  
  576. `W'
  577.      Forget the saved outside window configuration--so that the current
  578.      window configuration will remain unchanged when you next exit
  579.      Edebug (by continuing the program).  Also toggle the
  580.      `edebug-save-windows' variable.
  581.  
  582. 
  583. File: elisp,  Node: Edebug Eval,  Next: Eval List,  Prev: Views,  Up: Edebug
  584.  
  585. Evaluation
  586. ----------
  587.  
  588.    While within Edebug, you can evaluate expressions "as if" Edebug were
  589. not running.  Edebug tries to be invisible to the expression's
  590. evaluation.
  591.  
  592. `e EXP RET'
  593.      Evaluate expression EXP in the context outside of Edebug.  That
  594.      is, Edebug tries to avoid altering the effect of EXP.
  595.  
  596. `M-ESC EXP RET'
  597.      Evaluate expression EXP in the context of Edebug itself.
  598.  
  599. `C-x C-e'
  600.      Evaluate the expression in the buffer before point, in the context
  601.      outside of Edebug.
  602.  
  603. 
  604. File: elisp,  Node: Eval List,  Next: Edebug Misc,  Prev: Edebug Eval,  Up: Edebug
  605.  
  606. Evaluation List Buffer
  607. ----------------------
  608.  
  609.    You can use the "evaluation list buffer", called `*edebug*', to
  610. evaluate expressions interactively.  You can also set up the
  611. "evaluation list" of expressions to be evaluated automatically each
  612. time Edebug is reentered.
  613.  
  614. `E'
  615.      Switch to the evaluation list buffer `*edebug*'.
  616.  
  617.    In the `*edebug*' buffer you can use the commands of Lisp
  618. Interaction as well as these special commands:
  619.  
  620. `LFD'
  621.      Evaluate the expression before point, in the context outside of
  622.      Edebug, and insert the value in the buffer.
  623.  
  624. `C-x C-e'
  625.      Evaluate the expression before point, in the context outside of
  626.      Edebug.
  627.  
  628. `C-c C-u'
  629.      Build a new evaluation list from the first expression of each
  630.      group, reevaluate and redisplay.  Groups are separated by a line
  631.      starting with a comment.
  632.  
  633. `C-c C-d'
  634.      Delete the evaluation list group that point is in.
  635.  
  636. `C-c C-w'
  637.      Switch back to the Edebug buffer at the current stop point.
  638.  
  639.    You can evaluate expressions in the evaluation list window with
  640. `LFD' or `C-x C-e', just as you would in `*scratch*'; but they are
  641. evaluated in the context outside of Edebug.
  642.  
  643.    The expressions you enter interactively (and their results) are lost
  644. when you continue execution of your function unless you add them to the
  645. evaluation list with `C-c C-u' (`edebug-update-eval-list').  This
  646. command builds a new list from the first expression of each "evaluation
  647. list group".  Groups are separated by a line starting with a comment.
  648.  
  649.    When the evaluation list is redisplayed, each expression is displayed
  650. followed by the result of evaluating it, and a comment line.  If an
  651. error occurs during an evaluation, the error message is displayed in a
  652. string as if it were the result.  Therefore expressions that use
  653. variables not currently valid do not interrupt your debugging.
  654.  
  655.    Here is an example of what the evaluation list window looks like
  656. after several expressions have been added to it:
  657.  
  658.      (current-buffer)
  659.      #<buffer *scratch*>
  660.      ;---------------------------------------------------------------
  661.      (point-min)
  662.      1
  663.      ;---------------------------------------------------------------
  664.      (point-max)
  665.      2
  666.      ;---------------------------------------------------------------
  667.      edebug-outside-point-max
  668.      "Symbol's value as variable is void: edebug-outside-point-max"
  669.      ;---------------------------------------------------------------
  670.      (recursion-depth)
  671.      0
  672.      ;---------------------------------------------------------------
  673.      this-command
  674.      eval-last-sexp
  675.      ;---------------------------------------------------------------
  676.  
  677.    To delete a group, move point into it and type `C-c C-d'
  678. (`edebug-delete-eval-item'), or simply delete the text for it and
  679. update the evaluation list with `C-c C-u'.  When you add a new group,
  680. be sure to add a comment at the beginning.
  681.  
  682.    After selecting `*edebug*', you can return to the source code buffer
  683. (the Edebug buffer) with `C-c C-w'.  The `*edebug*' buffer is killed
  684. when you continue execution of your function, and recreated next time
  685. it is needed.
  686.  
  687. 
  688. File: elisp,  Node: Printing,  Next: The Outside Context,  Prev: Edebug Misc,  Up: Edebug
  689.  
  690. Printing
  691. --------
  692.  
  693.    If the results of your expressions contain circular references to
  694. other parts of the same structure, you can print them more usefully
  695. with the `custom-print'.
  696.  
  697.    To load the package and activate custom printing only for Edebug,
  698. simply use the command `edebug-install-custom-print-funcs'.  Then set
  699. the variable `print-circle' to enable special handling of circular
  700. structure.  To restore the standard print functions, use
  701. `edebug-reset-print-funcs'.
  702.  
  703. 
  704. File: elisp,  Node: The Outside Context,  Next: Macro Calls,  Prev: Printing,  Up: Edebug
  705.  
  706. The Outside Context
  707. -------------------
  708.  
  709.    Edebug tries to be transparent to the program you are debugging, but
  710. it does not succeed completely.  In addition, most evaluations you do
  711. within Edebug (see *Note Evaluation::) occur in the same outside context
  712. which is temporarily restored for the evaluation.  This section explains
  713. precisely how use Edebug fails to be completely transparent.
  714.  
  715. * Menu:
  716.  
  717. * Just Checking::        Just Checking
  718. * Outside Window Configuration::  Outside Window Configuration
  719. * Recursive Edit::        Recursive Edit
  720. * Side Effects::        Side Effects
  721.  
  722. 
  723. File: elisp,  Node: Just Checking,  Next: Outside Window Configuration,  Up: The Outside Context
  724.  
  725. Just Checking
  726. .............
  727.  
  728.    Whenever Edebug is entered just to think about whether to take some
  729. action, it needs to save and restore certain data.
  730.  
  731.    * `max-lisp-eval-depth' and `max-specpdl-size' are both incremented
  732.      for each `edebug-enter' call so that your code should not be
  733.      impacted by Edebug frames on the stack.
  734.  
  735.    * The state of keyboard macro execution is saved and cleared out.
  736.  
  737. 
  738. File: elisp,  Node: Outside Window Configuration,  Next: Recursive Edit,  Prev: Just Checking,  Up: The Outside Context
  739.  
  740. Outside Window Configuration
  741. ............................
  742.  
  743.    When Edebug needs to display something (e.g., in trace mode), it
  744. saves the current window configuration from "outside" Edebug (*note
  745. Window Configurations::.).  When you exit Edebug (by continuing the
  746. program), it restores the previous window configuration.
  747.  
  748.    Emacs redisplays only when it pauses.  Usually, when you continue
  749. Edebug, the program comes back into Edebug at a breakpoint or after
  750. stepping, without pausing or reading input in between.  In such cases,
  751. Emacs never gets a chance to redisplay the "outside" configuration.
  752. What you see is the window configuration for within Edebug, with no
  753. interruption.
  754.  
  755.    The window configuration proper does not include which buffer is
  756. current or where point and mark are in the current buffer, but Edebug
  757. saves and restores these also.
  758.  
  759.    Entry to Edebug for displaying something also saves and restores the
  760. following data.  (Some of these variables are deliberately not restored
  761. if an error or quit signal occurs.)
  762.  
  763.    * The position of point in the Edebug buffer is saved and restored
  764.      if the outside current buffer is the same as the Edebug buffer.
  765.  
  766.    * The outside window configuration, as described above, is saved and
  767.      restored if `edebug-save-windows' is non-`nil'.
  768.  
  769.    * The current buffer, and point and mark in the current buffer are
  770.      normally saved and restored even if the current buffer is the same
  771.      as the Edebug buffer.
  772.  
  773.    * The value of point in each displayed buffers is saved and restored
  774.      if `edebug-save-displayed-buffer-points' is non-`nil'.
  775.  
  776.    * The variables `overlay-arrow-position' and `overlay-arrow-string'
  777.      are saved and restored.  This permits recursive use of Edebug, and
  778.      use of Edebug while using GUD.
  779.  
  780.    * `cursor-in-echo-area' is locally bound to `nil' so that the cursor
  781.      shows up in the window.
  782.  
  783. 
  784. File: elisp,  Node: Recursive Edit,  Next: Side Effects,  Prev: Outside Window Configuration,  Up: The Outside Context
  785.  
  786. Recursive Edit
  787. ..............
  788.  
  789.    When Edebug is entered and actually reads commands from the user, it
  790. saves (and later restores) these additional data:
  791.  
  792.    * The current match data, for whichever buffer was current.
  793.  
  794.    * `last-command', `this-command', `last-command-char', and
  795.      `last-input-char'.  Commands used within Edebug do not affect these
  796.      variables outside of Edebug.
  797.  
  798.      But note that it is not possible to preserve the status reported by
  799.      `(this-command-keys)' and the variable `unread-command-char'.
  800.  
  801.    * `standard-output' and `standard-input'.
  802.  
  803. 
  804. File: elisp,  Node: Side Effects,  Prev: Recursive Edit,  Up: The Outside Context
  805.  
  806. Side Effects
  807. ............
  808.  
  809.    Edebug operation unavoidably alters some data in Emacs, and this can
  810. interfere with debugging certain programs.
  811.  
  812.    * Lisp stack usage is increased, but the limits,
  813.      `max-lisp-eval-depth' and `max-specpdl-size', are also increased
  814.      proportionally.
  815.  
  816.    * The key sequence returned by `this-command-keys' is changed by
  817.      executing commands within Edebug and there appears to be no way to
  818.      reset the key sequence from Lisp.
  819.  
  820.    * Edebug cannot save and restore the value of `unread-command-char'
  821.      or `unread-command-events'.  Entering Edebug while these variables
  822.      have nontrivial values can interfere with execution of the program
  823.      you are debugging.
  824.  
  825.    * Complex commands executed while in Edebug are added to the variable
  826.      `command-history'.  In rare cases this can alter execution.
  827.  
  828.    * Within Edebug, the recursion depth appears one deeper than the
  829.      recursion depth outside Edebug.
  830.  
  831.    * Horizontal scrolling of the Edebug buffer is not recovered.
  832.  
  833. 
  834. File: elisp,  Node: Macro Calls,  Next: Edebug Options,  Prev: The Outside Context,  Up: Edebug
  835.  
  836. Macro Calls
  837. -----------
  838.  
  839.    When Edebug prepares for stepping through an expression that uses a
  840. Lisp macro, it needs additional advice to do the job properly.  This is
  841. because there is no way to tell which parts of the macro call are forms
  842. to be evaluated.  You must explain the format of calls to each macro to
  843. enable Edebug to handle it.  To do this, use `def-edebug-form-spec' to
  844. define the format of calls to a given macro.
  845.  
  846.  - Macro: def-edebug-form-spec MACRO ARGPATTERN
  847.      Specify which parts of a call to macro MACRO are subexpressions to
  848.      be evaluated.  The second argument, ARGPATTERN, details what the
  849.      argument list looks like.
  850.  
  851.    Here is a table of the possibilities for ARGPATTERN and its
  852. subexpressions:
  853.  
  854. `t'
  855.      A list of any number of evaluated arguments.
  856.  
  857. `0'
  858.      A list of unevaluated arguments.
  859.  
  860. `sexp'
  861.      A single unevaluated object.
  862.  
  863. `form'
  864.      A single evaluated expression.
  865.  
  866. `symbolp'
  867.      An unevaluated symbol.
  868.  
  869. `integerp'
  870.      An unevaluated number.
  871.  
  872. `stringp'
  873.      An unevaluated string.
  874.  
  875. `vectorp'
  876.      An unevaluated vector.
  877.  
  878. `atom'
  879.      An unevaluated object that is not a cons cell.
  880.  
  881. `function'
  882.      A function argument: a quoted symbol, a quoted lambda expression,
  883.      or a form (that should evaluate to a function or lambda
  884.      expression).  Edebug treats the body of a lambda expression
  885.      treated as evaluated.
  886.  
  887. `FUNCTION'
  888.      A function serves as a predicate--it designates the set of possible
  889.      arguments for which it would return non-`nil'.
  890.  
  891. `'OBJECT'
  892.      The precise object OBJECT, treated as unevaluated.
  893.  
  894. `(PATTERNS)'
  895.      A list whose elements are described by PATTERNS.  A sublist of the
  896.      same format as the top level, processed recursively.
  897.  
  898. `[PATTERNS]'
  899.      A sequence of arguments that are described by PATTERNS.
  900.  
  901. `&optional'
  902.      This symbol serves as a flag saying that all following elements in
  903.      the specification list at this level are optional.  They may or
  904.      may not match arguments; as soon as one does not match, processing
  905.      of the specification list at this level terminates.  To make just
  906.      one item optional, use `[&optional PATTERN]'.
  907.  
  908. `&rest'
  909.      This symbol serves as a flag saying that the following elements in
  910.      the specification list at this level may be repeated, in order,
  911.      zero or more times.  Only one `&rest' may appear at the same level
  912.      of a specification list, and `&rest' must not be followed by
  913.      `&optional'.
  914.  
  915.      To specify repetition of certain types of arguments, followed by
  916.      dissimilar arguments, use `[&rest PATTERNS...]'.
  917.  
  918. `&or'
  919.      This symbol serves as an operator saying that the following
  920.      elements in the specification list at this level are alternatives.
  921.      To group two or more list elements as one alternative, bracket
  922.      them in `[...]'.  Only one `&or' may appear in a list, and it may
  923.      not be followed by `&optional' or `&rest'.  One of the
  924.      alternatives must match, unless the `&or' is preceded by
  925.      `&optional' or `&rest'.
  926.  
  927.    If the actual arguments of a macro call fail to match the
  928. specification, taking account of alternatives, optional arguments and
  929. repeated arguments, Edebug reports a syntax error in use of the macro.
  930.  
  931.    The combination of backtracking, `&optional', `&rest', `&or', and
  932. `[...]' for grouping provides the equivalent of regular expressions.
  933. The `(...)' lists require balanced parentheses, which is the only
  934. context free (finite state with stack) construct supported.
  935.  
  936.    Here are some examples of using `def-edebug-form-spec'.  First, for
  937. the `let' special form:
  938.  
  939.      (def-edebug-form-spec let
  940.        '((&rest
  941.          &or symbolp (symbolp &optional form))
  942.         &rest form))
  943.  
  944.    Here's the spec for the `for' loop macro (*note Problems with
  945. Macros::.) and for the `case' and `do' macros in `cl.el':
  946.  
  947.      (def-edebug-form-spec for
  948.        '(symbolp 'from form 'to form 'do &rest form))
  949.      
  950.      (def-edebug-form-spec case
  951.        '(form &rest (sexp form)))
  952.      
  953.      (def-edebug-form-spec do
  954.        '((&rest &or symbolp (symbolp &optional form form))
  955.          (form &rest form)
  956.          &rest body))
  957.  
  958.    Finally, the functions `mapcar', `mapconcat', `mapatoms', `apply',
  959. and `funcall' all take function arguments, and Edebug defines
  960. specifications for them.  Here's one example:
  961.  
  962.      (def-edebug-form-spec apply '(function &rest form))
  963.  
  964.    The backquote (``') macro results in an expression that is not
  965. necessarily evaluated.  Edebug cannot step through code generated by use
  966. of backquote.
  967.  
  968. 
  969. File: elisp,  Node: Edebug Options,  Prev: Macro Calls,  Up: Edebug
  970.  
  971. Edebug Options
  972. --------------
  973.  
  974.    These options affect the behavior of Edebug:
  975.  
  976.  - User Option: edebug-all-defuns
  977.      If non-`nil', normal evaluation of `defun' and `defmacro' forms
  978.      prepares the functions and macros for stepping with Edebug.  This
  979.      applies to `eval-defun', `eval-region' and `eval-current-buffer'.
  980.  
  981.      The default value is `nil'.
  982.  
  983.  - User Option: edebug-stop-before-symbols
  984.      If non-`nil', Edebug places stop points before symbols as well as
  985.      after.
  986.  
  987.      This option takes effect for a function when you prepare it for
  988.      stepping with Edebug.  Changing the option's value during
  989.      execution of Edebug has no effect on the functions already set up
  990.      for Edebug execution.
  991.  
  992.  - User Option: edebug-save-windows
  993.      If non-`nil', save and restore window configuration on Edebug
  994.      calls.  It takes some time to save and restore, so if your program
  995.      does not care what happens to the window configurations, it is
  996.      better to set this variable to `nil'.
  997.  
  998.      The default value is `t'.
  999.  
  1000.  - User Option: edebug-save-point
  1001.      If non-`nil', Edebug saves and restores point and the mark in
  1002.      source code buffers.  The default value is `t'.
  1003.  
  1004.  - User Option: edebug-save-displayed-buffer-points
  1005.      If non-`nil', save and restore point in all buffers when entering
  1006.      Edebug mode.
  1007.  
  1008.      Saving and restoring point in other buffers is necessary if you are
  1009.      debugging code that changes the point of a buffer which is
  1010.      displayed in a non-selected window.  If Edebug or the user then
  1011.      selects the window, the buffer's point will be changed to the
  1012.      window's point.
  1013.  
  1014.      Saving and restoring is an expensive operation since it visits each
  1015.      window and each displayed buffer twice for each Edebug call, so it
  1016.      is best to avoid it if you can.
  1017.  
  1018.      The default value is `nil'.
  1019.  
  1020.  - User Option: edebug-initial-mode
  1021.      If this variable is non-`nil', it specifies an Edebug mode to start
  1022.      in each time the program enters a new Edebug recursive-edit level.
  1023.      Possible values are `step', `go', `Go-nonstop', `trace',
  1024.      `Trace-fast', `continue', and `Continue-fast'.
  1025.  
  1026.      The default value is `step'.
  1027.  
  1028.  - User Option: edebug-trace
  1029.      Non-`nil' means display a trace of function entry and exit.
  1030.      Tracing output is displayed in a buffer named `*edebug-trace*', one
  1031.      function entry or exit per line, indented by the recursion level.
  1032.      You can customize this display by replacing the functions
  1033.      `edebug-print-trace-entry' and `edebug-print-trace-exit'.
  1034.  
  1035.      The default value is `nil'.
  1036.  
  1037. 
  1038. File: elisp,  Node: Streams,  Next: Minibuffers,  Prev: Debugging,  Up: Top
  1039.  
  1040. Reading and Printing Lisp Objects
  1041. *********************************
  1042.  
  1043.    "Printing" and "reading" are the operations of converting Lisp
  1044. objects to textual form and vice versa.  They use the printed
  1045. representations and read syntax described in *Note Types of Lisp
  1046. Object::.
  1047.  
  1048.    This chapter describes the Lisp functions for reading and printing.
  1049. It also describes "streams", which specify where to get the text (if
  1050. reading) or where to put it (if printing).
  1051.  
  1052. * Menu:
  1053.  
  1054. * Streams Intro::     Overview of streams, reading and printing.
  1055. * Input Streams::     Various data types that can be used as input streams.
  1056. * Input Functions::   Functions to read Lisp objects from text.
  1057. * Output Streams::    Various data types that can be used as output streams.
  1058. * Output Functions::  Functions to print Lisp objects as text.
  1059. * Output Variables::  Variables that control what the printing functions do.
  1060.  
  1061. 
  1062. File: elisp,  Node: Streams Intro,  Next: Input Streams,  Up: Streams
  1063.  
  1064. Introduction to Reading and Printing
  1065. ====================================
  1066.  
  1067.    "Reading" a Lisp object means parsing a Lisp expression in textual
  1068. form and producing a corresponding Lisp object.  This is how Lisp
  1069. programs get into Lisp from files of Lisp code.  We call the text the
  1070. "read syntax" of the object.  For example, reading the text `(a . 5)'
  1071. returns a cons cell whose CAR is `a' and whose CDR is the number 5.
  1072.  
  1073.    "Printing" a Lisp object means producing text that represents that
  1074. object--converting the object to its printed representation.  Printing
  1075. the cons cell described above produces the text `(a . 5)'.
  1076.  
  1077.    Reading and printing are more or less inverse operations: printing
  1078. the object that results from reading a given piece of text often
  1079. produces the same text, and reading the text that results from printing
  1080. an object usually produces a similar-looking object.  For example,
  1081. printing the symbol `foo' produces the text `foo', and reading that text
  1082. returns the symbol `foo'.  Printing a list whose elements are `a' and
  1083. `b' produces the text `(a b)', and reading that text produces a list
  1084. (but not the same list) with elements are `a' and `b'.
  1085.  
  1086.    However, these two operations are not precisely inverses.  There are
  1087. two kinds of exceptions:
  1088.  
  1089.    * Printing can produce text that cannot be read.  For example,
  1090.      buffers, windows, subprocesses and markers print into text that
  1091.      starts with `#'; if you try to read this text, you get an error.
  1092.      There is no way to read those data types.
  1093.  
  1094.    * One object can have multiple textual representations.  For example,
  1095.      `1' and `01' represent the same integer, and `(a b)' and `(a .
  1096.      (b))' represent the same list.  Reading will accept any of the
  1097.      alternatives, but printing must choose one of them.
  1098.  
  1099. 
  1100. File: elisp,  Node: Input Streams,  Next: Input Functions,  Prev: Streams Intro,  Up: Streams
  1101.  
  1102. Input Streams
  1103. =============
  1104.  
  1105.    Most of the Lisp functions for reading text take an "input stream"
  1106. as an argument.  The input stream specifies where or how to get the
  1107. characters of the text to be read.  Here are the possible types of input
  1108. stream:
  1109.  
  1110. BUFFER
  1111.      The input characters are read from BUFFER, starting with the
  1112.      character directly after point.  Point advances as characters are
  1113.      read.
  1114.  
  1115. MARKER
  1116.      The input characters are read from the buffer that MARKER is in,
  1117.      starting with the character directly after the marker.  The marker
  1118.      position advances as characters are read.  The value of point in
  1119.      the buffer has no effect when the stream is a marker.
  1120.  
  1121. STRING
  1122.      The input characters are taken from STRING, starting at the first
  1123.      character in the string and using as many characters as required.
  1124.  
  1125. FUNCTION
  1126.      The input characters are generated by FUNCTION, one character per
  1127.      call.  Normally FUNCTION is called with no arguments, and should
  1128.      return a character.
  1129.  
  1130.      Occasionally FUNCTION is called with one argument (always a
  1131.      character).  When that happens, FUNCTION should save the argument
  1132.      and arrange to return it on the next call.  This is called
  1133.      "unreading" the character; it happens when the Lisp reader reads
  1134.      one character too many and want to "put it back where it came
  1135.      from".
  1136.  
  1137. `t'
  1138.      `t' used as a stream means that the input is read from the
  1139.      minibuffer.  In fact, the minibuffer is invoked once and the text
  1140.      given by the user is made into a string that is then used as the
  1141.      input stream.
  1142.  
  1143. `nil'
  1144.      `nil' used as a stream means that the value of `standard-input'
  1145.      should be used instead; that value is the "default input stream",
  1146.      and must be a non-`nil' input stream.
  1147.  
  1148. SYMBOL
  1149.      A symbol as output stream is equivalent to the symbol's function
  1150.      definition (if any).
  1151.  
  1152.    Here is an example of reading from a stream which is a buffer,
  1153. showing where point is located before and after:
  1154.  
  1155.      ---------- Buffer: foo ----------
  1156.      This-!- is the contents of foo.
  1157.      ---------- Buffer: foo ----------
  1158.      
  1159.      (read (get-buffer "foo"))
  1160.           => is
  1161.      (read (get-buffer "foo"))
  1162.           => the
  1163.      
  1164.      ---------- Buffer: foo ----------
  1165.      This is the-!- contents of foo.
  1166.      ---------- Buffer: foo ----------
  1167.  
  1168. Note that the first read skips a space at the beginning of the buffer.
  1169. Reading skips any amount of whitespace preceding the significant text.
  1170.  
  1171.    In Emacs 18, reading a symbol discarded the delimiter terminating the
  1172. symbol.  Thus, point would end up at the beginning of `contents' rather
  1173. than after `the'.  The Emacs 19 behavior is superior because it
  1174. correctly handles input such as `bar(foo)' where the delimiter that
  1175. ends one object is needed as the beginning of another object.
  1176.  
  1177.    Here is an example of reading from a stream that is a marker,
  1178. initialized to point at the beginning of the buffer shown.  The value
  1179. read is the symbol `This'.
  1180.  
  1181.  
  1182.      ---------- Buffer: foo ----------
  1183.      This is the contents of foo.
  1184.      ---------- Buffer: foo ----------
  1185.      
  1186.      (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
  1187.           => #<marker at 1 in foo>
  1188.      (read m)
  1189.           => This
  1190.      m
  1191.           => #<marker at 6 in foo>   ;; After the first space.
  1192.  
  1193.    Here we read from the contents of a string:
  1194.  
  1195.      (read "(When in) the course")
  1196.           => (When in)
  1197.  
  1198.    The following example reads from the minibuffer.  The prompt is:
  1199. `Lisp expression: '.  (That is always the prompt used when you read
  1200. from the stream `t'.)  The user's input is shown following the prompt.
  1201.  
  1202.      (read t)
  1203.           => 23
  1204.      ---------- Buffer: Minibuffer ----------
  1205.      Lisp expression: `23 RET'
  1206.      ---------- Buffer: Minibuffer ----------
  1207.  
  1208.    Finally, here is an example of a stream that is a function, named
  1209. `useless-stream'.  Before we use the stream, we initialize the variable
  1210. `useless-list' to a list of characters.  Then each call to the function
  1211. `useless-stream' obtains the next characters in the list or unreads a
  1212. character by adding it to the front of the list.
  1213.  
  1214.      (setq useless-list (append "XY()" nil))
  1215.           => (88 89 40 41)
  1216.      
  1217.      (defun useless-stream (&optional unread)
  1218.        (if unread
  1219.            (setq useless-list (cons unread useless-list))
  1220.          (prog1 (car useless-list)
  1221.                 (setq useless-list (cdr useless-list)))))
  1222.           => useless-stream
  1223.  
  1224. Now we read using the stream thus constructed:
  1225.  
  1226.      (read 'useless-stream)
  1227.           => XY
  1228.      
  1229.      useless-list
  1230.           => (41)
  1231.  
  1232. Note that the close parenthesis remains in the list.  The reader has
  1233. read it, discovered that it ended the input, and unread it.  Another
  1234. attempt to read from the stream at this point would get an error due to
  1235. the unmatched close parenthesis.
  1236.  
  1237.  - Function: get-file-char
  1238.      This function is used internally as an input stream to read from
  1239.      the input file opened by the function `load'.  Don't use this
  1240.      function yourself.
  1241.  
  1242. 
  1243. File: elisp,  Node: Input Functions,  Next: Output Streams,  Prev: Input Streams,  Up: Streams
  1244.  
  1245. Input Functions
  1246. ===============
  1247.  
  1248.    This section describes the Lisp functions and variables that pertain
  1249. to reading.
  1250.  
  1251.    In the functions below, STREAM stands for an input stream (see the
  1252. previous section).  If STREAM is `nil' or omitted, it defaults to the
  1253. value of `standard-input'.
  1254.  
  1255.    An `end-of-file' error results if an unterminated list or vector is
  1256. found.
  1257.  
  1258.  - Function: read &optional STREAM
  1259.      This function reads one textual Lisp expression from STREAM,
  1260.      returning it as a Lisp object.  This is the basic Lisp input
  1261.      function.
  1262.  
  1263.  - Function: read-from-string STRING &optional START END
  1264.      This function reads the first textual Lisp expression from the
  1265.      text in STRING.  It returns a cons cell whose CAR is that
  1266.      expression, and whose CDR is an integer giving the position of the
  1267.      next remaining character in the string (i.e., the first one not
  1268.      read).
  1269.  
  1270.      If START is supplied, then reading begins at index START in the
  1271.      string (where the first character is at index 0).  If END is also
  1272.      supplied, then reading stops at that index as if the rest of the
  1273.      string were not there.
  1274.  
  1275.      For example:
  1276.  
  1277.           (read-from-string "(setq x 55) (setq y 5)")
  1278.                => ((setq x 55) . 11)
  1279.           (read-from-string "\"A short string\"")
  1280.                => ("A short string" . 16)
  1281.           
  1282.           ;; Read starting at the first character.
  1283.           (read-from-string "(list 112)" 0)
  1284.                => ((list 112) . 10)
  1285.           ;; Read starting at the second character.
  1286.           (read-from-string "(list 112)" 1)
  1287.                => (list . 6)
  1288.           ;; Read starting at the seventh character,
  1289.           ;;   and stopping at the ninth.
  1290.           (read-from-string "(list 112)" 6 8)
  1291.                => (11 . 8)
  1292.  
  1293.  - Variable: standard-input
  1294.      This variable holds the default input stream: the stream that
  1295.      `read' uses when the STREAM argument is `nil'.
  1296.  
  1297.